﻿// <copyright file="TTableEntityTransactionInfoTest.cs" company="N/A">
//     Copyright (c) Nicholas Barrett and Benjamin Kasten.  All rights reserved.
//
//     This program is free software; you can redistribute it and/or modify it
//     under the terms of the GNU General Public License as published by the
//     Free Software Foundation; either version 2 of the License, or (at your
//     option) any later version.
//
//     This program is distributed in the hope that it will be useful, but
//     WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
//     Public License for more details.
//
//     You should have received a copy of the GNU General Public License along
//     with this program; if not, write to the Free Software Foundation, 
//     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// </copyright>

namespace BetterAzureTableStorage.Tests
{
    using System;
    using System.Data.Services.Client;
    using System.Net;
    using BetterAzureTableStorage;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// This is a test class for TTableEntityTransactionInfoTest and is intended
    /// to contain all TTableEntityTransactionInfoTest Unit Tests
    /// </summary>
    [TestClass()]
    public class TTableEntityTransactionInfoTest
    {
        /// <summary>
        /// A test for TTableEntityTransactionInfo Constructor
        /// </summary>
        [TestMethod()]
        public void TTableEntityTransactionInfoConstructorTest()
        {
            ITableEntity entity = new TTestTableEntityDot(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow);
            EntityStates state = EntityStates.Added;
            TTableEntityTransactionInfo target = new TTableEntityTransactionInfo(entity, state);
            Assert.AreEqual<ITableEntity>(entity, target.Entity);
            Assert.AreEqual<EntityStates>(state, target.State);
        }

        /// <summary>
        /// A test for ContentID
        /// </summary>
        [TestMethod()]
        public void ContentIDTest()
        {
            ITableEntity entity = new TTestTableEntityFoo();
            EntityStates state = EntityStates.Added;
            TTableEntityTransactionInfo target = new TTableEntityTransactionInfo(entity, state);
            int expected = 24;
            int actual;
            target.ContentID = expected;
            actual = target.ContentID;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        /// A test for Entity
        /// </summary>
        [TestMethod()]
        public void EntityTest()
        {
            ITableEntity entity = new TTestTableEntityFoo();
            EntityStates state = EntityStates.Added;
            TTableEntityTransactionInfo target = new TTableEntityTransactionInfo(entity, state);
            Assert.AreEqual<ITableEntity>(entity, target.Entity);
            ITableEntity expected = new TTestTableEntityBar();
            ITableEntity actual;
            target.Entity = expected;
            actual = target.Entity;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        /// A test for OnFailure
        /// </summary>
        [TestMethod()]
        public void OnFailureTest()
        {
            int contentID = 29;
            ITableEntity entity = new TTestTableEntityFoo();
            EntityStates state = EntityStates.Added;
            TTableEntityTransactionInfo target = new TTableEntityTransactionInfo(entity, state);
            Action<TTableEntityTransactionInfo> expected = (info) => { info.ContentID = contentID; };
            Action<TTableEntityTransactionInfo> actual;
            target.OnFailure = expected;
            actual = target.OnFailure;
            Assert.AreEqual(expected, actual);
            actual(target);
            Assert.AreEqual<int>(contentID, target.ContentID);
        }

        /// <summary>
        /// A test for OnSuccess
        /// </summary>
        [TestMethod()]
        public void OnSuccessTest()
        {
            int contentID = 234;
            ITableEntity entity = new TTestTableEntityFoo();
            EntityStates state = EntityStates.Added;
            TTableEntityTransactionInfo target = new TTableEntityTransactionInfo(entity, state);
            Action<TTableEntityTransactionInfo> expected = (info) => { info.ContentID = contentID; };
            Action<TTableEntityTransactionInfo> actual;
            target.OnSuccess = expected;
            actual = target.OnSuccess;
            Assert.AreEqual(expected, actual);
            actual(target);
            Assert.AreEqual<int>(contentID, target.ContentID);
        }

        /// <summary>
        /// A test for SetName
        /// </summary>
        [TestMethod()]
        public void SetNameTest()
        {
            ITableEntity entity = new TTestTableEntityFoo();
            EntityStates state = EntityStates.Added;
            TTableEntityTransactionInfo target = new TTableEntityTransactionInfo(entity, state);
            string expected = "testSetName";
            string actual;
            target.SetName = expected;
            actual = target.SetName;
            Assert.AreEqual<string>(expected, actual);
        }

        /// <summary>
        /// A test for State
        /// </summary>
        [TestMethod()]
        public void StateTest()
        {
            ITableEntity entity = new TTestTableEntityFoo();
            EntityStates state = EntityStates.Added;
            TTableEntityTransactionInfo target = new TTableEntityTransactionInfo(entity, state);
            EntityStates expected = EntityStates.Deleted;
            EntityStates actual;
            target.State = expected;
            actual = target.State;
            Assert.AreEqual<EntityStates>(expected, actual);
        }

        /// <summary>
        /// A test for SuccessCode
        /// </summary>
        [TestMethod()]
        public void SuccessCodeTest()
        {
            ITableEntity entity = new TTestTableEntityFoo();
            EntityStates state = EntityStates.Added;
            TTableEntityTransactionInfo target = new TTableEntityTransactionInfo(entity, state);
            HttpStatusCode expected = HttpStatusCode.Accepted;
            HttpStatusCode actual;
            target.SuccessCode = expected;
            actual = target.SuccessCode;
            Assert.AreEqual<HttpStatusCode>(expected, actual);
        }

        /// <summary>
        /// A test for Verb
        /// </summary>
        [TestMethod()]
        public void VerbTest()
        {
            ITableEntity entity = new TTestTableEntityFoo();
            EntityStates state = EntityStates.Added;
            TTableEntityTransactionInfo target = new TTableEntityTransactionInfo(entity, state);
            string expected = HttpConstants.Post;
            string actual;
            target.Verb = expected;
            actual = target.Verb;
            Assert.AreEqual<string>(expected, actual);
        }
    }
}
